// Package utils
package utils

import (
	"log"
	"reflect"

	"git.oschina.net/baayso/gobms/core/utils/config"
)

var Conf *config.Config = nil

func init() {
	conf, err := config.LoadConfigFile("conf/sys.json")
	if err != nil {
		log.Fatalf("Fail: %v\n", err)
	}

	Conf = conf
}

//
func ToSlice(arr interface{}) []interface{} {
	v := reflect.ValueOf(arr)

	if v.Kind() != reflect.Slice {
		panic("toslice arr not slice")
	}

	length := v.Len()

	ret := make([]interface{}, length)

	for i := 0; i < length; i++ {
		ret[i] = v.Index(i).Interface()
	}

	return ret
}

//
func CheckError(err error) {
	if err != nil {
		log.Printf("Fail: %v\n", err)
	}
}
